JavaScript has always been a mysterious thing for me, especially in error handling. Writing JavaScript before Firefox came out is really a headache. If the program runs successfully, I had to carefully check the program and use Alert repeatedly to verify whether each piece of code is running normally, which is time-consuming and laborious. Maybe many people laugh at me. Why don't I need some debugging softw
JavaScript uses onerror to set the default image display instead of alt and javascriptonerror.
JavaScript code
// Processing function errorImg (img) {img. src = "img .jpg"; img. onerror = null ;}
Html code
For the sake of beauty, when the webpage image does not exist, the cross image is not displayed
When displayed on
1 onerror Event Description Using the OnError event is an old-fashioned standard method of capturing JavaScript errors in Web pages 2 when to generate OnError events A onerror event is generated whenever a script error occurs on the page 3 How to use the
1
,
Window. onerror
Event
The onerror event is used to help handle JavaScript errors on the page. When an exception occurs on the page, the error event is triggered on the window object. For example:
In this case, the browser displays the error message:
.
If you do not want the browser to Display error messages in the default dialog box, let the
1
,
Window.onerror
Events
The OnError event is used to assist in processing JavaScript errors on the page. When an exception occurs on the page, the error event is triggered on the Window object. For example:
In this case, the browser displays an error message:
。
If you do not want the browser to display an error message in the default dialog box, let the
JavaScript code
Processing function when an image load Error
errorimg (img) {
IMG.SRC = "default picture. jpg";
Img.onerror = null;
}
HTML code
In order to be beautiful when the Web page image does not exist when the fork picture is not displayed
When the page is displayed, if the picture is moved or lost, it will display a picture with X on the page, which affects the user's experience. Even if you use the ALT attribute to
You must have seen the Internet when the load failed red Fork picture, specific as. Of course, Google Chrome and Firefox will look good in their processing now.You can actually take advantage of the onerror event of the picture tag to handle it, requiring it to load a default picture immediately after it fails, instead of displaying it as a red fork.The code is as follows:Meaning, if loading s.png this picture fails, immediately to load xx.png this p
When capturing js errors, we usually use the try {} catch (e) {} method, and then obtain the error information through e. errorMessage and other methods, and then report the error. However, the onerror event may be rarely used. Have we considered how to report the row number of the error? If you have thought about whether this problem is also plagued by this problem, do you think it is impossible to capture the wrong row number in js? In fact, I encou
When capturing js errors, we usually use the try {} catch (e) {} method, and then obtain the error information through e. errorMessage and other methods, and then report the error. However, the onerror event may be rarely used. Have we considered how to report the row number of the error? If you have thought about whether this problem is also plagued by this problem, do you think it is impossible to capture the wrong row number in js? In fact, I encou
Javascriptwindow. onerror event learning new gains when capturing js errors, we usually use the try {} catch (e) {} method, and then use e. attackers can obtain error messages and report errors. However, the onerror event may be rarely used. Have we considered how to report the row number of the error? If you have thought about whether this problem is also plagued by this problem, do you think it is impossi
When the webpage is opened, Stackoverflowatline: 0 is displayed. Details of the onerror event of the img image. After analysis, we found that the webpage contains code similar to the following:
Analysis: pay special attention to onerror. When the image does not exist, onerror is triggered, while onerror specifies
Currently, when reporting js error information during window. onerror, sort out relevant information. For more information, see
Onerror syntax usage
Onerror has three input parameters by default:
• Msg: error message• Url: The file where the error is located• Line: the code line of the error, which is an integer.Window. oner
This article mainly introduces window. onerror: the method for capturing and reporting Js errors. if you need a friend, refer to a 2048 game user feedback in the next two days. after opening the game, you cannot play. there is only one game panel, and the number cannot be initialized, even more mobile, the device is iPhone 4 S, iOS 5.1. It is still difficult to enable Safari from startup. Because the game uses a lot of HTML5 features, it is roughly es
and terminate the subsequent program execution.3. onerror events cannot capture all errors. They can only capture out-of-function or in-function errors (?? What does this mean? It's not a joke), such as adasdf; function test () {aaaa;} can capture the error function test () {aaaa;} undefined by adasdf ;} undefined aaaa errors can be captured, but system errors cannot be captured for functiona test () {} or function test () dd.4. The
The example of this article describes the way JS uses onerror to catch exceptions. Share to everyone for your reference, specific as follows:
If you need to take advantage of the OnError event, you must create a function that handles the error. You can think of this function as the OnError event handler (onerror event
JS interception/capture global Error onerrorDuring mobile Web development, some problems that cannot be reproduced during real-machine testing may often occur during PC debugging. At this time, we need to intercept errors on the mobile phone and provide relevant output. The company and the Internet have similar tools/class libraries. However, if a pure simple debugging does not require the introduction of tools or class libraries, we only need to know the principle of global interception. The wi
Pipelines of Nancy (Before After OnError), pipelinesonerror1. Simple Description
Before: If null is returned, the interceptor transfers the initiative to the route. If Response object is returned, the route does not work.
After: no return value. You can modify or replace the current Response here.
OnError: the return value is similar to that of Before. The control code for triggering errors or exceptions ca
Mobile Web development process, in the real machine testing, often encounter some PC debugging can not reproduce the problem, at this time we need to intercept the phone on the error, and have the corresponding output. Companies and the Internet have similar tools/class libraries, but if a simple debugging, perhaps do not need to introduce tools or class libraries, we need to know the principle of global interception. It's really simple, window.onerror.Grammar:
Prompts Stack overflow at line:0 when opening a Web page. I made a screenshot as follows:
After analysis, found in the Web page is similar to the following code:
Analysis: Pay special attention to onerror, when the picture does not exist, will trigger OnError, and OnError for IMG To specify a nopic.gif picture. That is to say, the picture exists to display pi
After analysis, found in the Web page is similar to the following code:
Analysis: Pay special attention to onerror, when the picture does not exist, will trigger OnError, and OnError for IMG To specify a nopic.gif picture. That is to say, the picture exists to display pic.gif, the picture does not exist will show nopic.gif. But the problem is, if nopic.gif doe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.